<cfparam default="" name="PageType" />

<cfoutput>
<!---HTML header, css links, js links, and page title--->
#BASE.htmlHeader("", "css/style.css", "Elder's Program - Reports")#
<!---HTML header, css links, js links, and page title--->          

<h2>Master Activity - #url.DateFrom# to #url.DateTo#</h2>           
 
<!---QUERIES.masterActivity is set in showreport--->

<cfset masterActivityStruct = structNew() />

<cfloop list="#QUERIES.masterActivity.columnList#" index="i">
    <cfloop query="QUERIES.masterActivity">
        <cfset masterActivityStruct['#i#'] = evaluate("QUERIES.masterActivity.#i#")/>
        <cfbreak />
    </cfloop>
</cfloop> 

<cfset total = 0 />          	
<cfloop collection="#masterActivityStruct#" item="i">
    <cftry>
        <cfset total = total + masterActivityStruct['#i#'] />
    <cfcatch type="any">
        <cfset total = total + 0 />            
    </cfcatch>
    </cftry>
</cfloop>

<cfset masterActivityStruct['TotalSerivces'] = total />

<cfset serviceColumnStruct = {} />

<Cfset serviceColumnStruct['Services'] = {
    INHOMEVISIT = "In Home Visit", 
    GROUPVISIT = "Group Visit", 
    ESCORT = "Escort", 
    FAMILYSUPPORT = "Family Support",
    FOODASSISTANCE = "Food Assistance", 
    FOODBOX = "Food Box", 
    HEALTHPROMOTIONS = "Health Promotions",
    INFORMATION = "Information", 
    INPATIENTVISIT = "In Patient Visit",
    INTERPRETATION = "Interpretation", 
    MEDREFILLASSISTANCE = "Med Refil Assistance",
    TELEPHONING = "Telephoning", 
    WRITINGREADING = "Writing/Reading",
    OffSiteVisit = "Offsite Visit",
    ReferralService = "Referal",
    TTCM = "TTCM"
} />

<Cfset serviceColumnStruct['Billable Services'] = {
    MEDICALTRANSPORTATION = "Medical Transportation",
    CHORE = "Chore",
    DAYOFCARE = "Day of Care"
} />

<Cfset serviceColumnStruct['Family Caregiver'] = {
    INFORMATIONFCSI = "Information FCSI", ASSISTANCEFCSI = "Assistance FCSI"
} />

<Cfset serviceColumnStruct['Transportation'] = {
    ACTIVITIESOUTING = "Activities Outing", BANKING = "Banking", MEDICATIONPICKUP = "Medication Pickup",
    OTHERTRANSPORT = "Other", POTLUCK = "Potluck", SHOPPING = "Shopping"
} />

<Cfset serviceColumnStruct['DNKA/Cancellation'] = {
    DNKATRANSPORTATION = "DNKA Transportation", DNKAHOMEVISIT = "DNKA Home Visit", DNKAGROUPVISIT = "DNKA Group Visit", 
    CANCELLEDHOMEVISIT = "Cancellation Home Visit", CANCELLEDTRANSPORTATION = "Cancellation Transportation",
    CANCELLEDGROUPVISIT = "Cancellation Group Visit"
} />

<cfif PageType EQ "PDF" >
	
    <cfdocument format="pdf">

        <h2>Master Activity</h2>
        
        <table width="100%" cellspacing="2" style="font-size:14px;"><tbody><tr>
            <td valign="top">
                <table width="100%">
                    <thead>
                        <tr>
                            <th colspan="2" align="left">Billable Services</th>
                        </tr>
                        <tr>
                            <th colspan="2" align="left">&nbsp;</th>
                        </tr>
                        <tr>
                            <th align="left">Activity</th><th align="left">Count</th><th align="left">% of Total</th>
                        </tr>
                    </thead>
                   <cfloop collection="#serviceColumnStruct#" item="i">
                   <cfif i eq "Billable Services" OR i eq "Services">
                        <tbody>
                        <tr>
                        <td colspan="3"><strong>#i#</strong></td>
                        </tr>
                        <tr>
                        <td colspan="3"><hr style="border:1px solid ##000; background-color:##000"/></td>
                        </tr>
                        </tbody>                        
                        <cfloop collection="#serviceColumnStruct['#i#']#" item="j">                      
                            <tbody>
                                <tr>
                                    <td>#serviceColumnStruct['#i#']['#j#']#</td>
                                    <td>#masterActivityStruct['#j#']#</td>
                                    <cftry>
                                        <cfset percent = (masterActivityStruct['#j#'] / masterActivityStruct['TotalSerivces']) * 100/>
                                    <cfcatch type="any">
                                        <cfset percent = 0/>
                                    </cfcatch>
                                    </cftry>
                                    <td align="right">#NumberFormat(percent, "__.__")#</td>
                                </tr>
                            </tbody>
                        </cfloop>
                        <tr>
                        <td colspan="3">&nbsp;</td>
                        </tr>
                        <tr>
                        <td colspan="3">&nbsp;</td>
                        </tr>
                    </cfif>
                    </cfloop>                    
                </table>
            </td>
            <td>&nbsp;</td>
            <td valign="top">
                <table width="100%">
                    <thead>
                        <tr>
                            <th colspan="2" align="left">Billable Services</th>
                        </tr>
                        <tr>
                            <th colspan="2" align="left">&nbsp;</th>
                        </tr>
                        <tr>
                            <th align="left">Activity</th><th align="left">Count</th><th align="left">% of Total</th>
                        </tr>
                    </thead>
                    <cfloop collection="#serviceColumnStruct#" item="i">
                   <cfif i eq "Family Caregiver" OR i eq "DNKA/Cancellation" OR i eq "Transportation">
                        <tbody>
                        <tr>
                        <td colspan="3"><strong>#i#</strong></td>
                        </tr>
                        <tr>
                        <td colspan="3"><hr style="border:1px solid ##000; background-color:##000"/></td>
                        </tr>
                        </tbody>                        
                        <cfloop collection="#serviceColumnStruct['#i#']#" item="j">                    
                            <tbody>
                                <tr>
                                    <td>#serviceColumnStruct['#i#']['#j#']#</td>
                                    <td>#masterActivityStruct['#j#']#</td>
                                    <cftry>
                                        <cfset percent = (masterActivityStruct['#j#'] / masterActivityStruct['TotalSerivces']) * 100/>
                                    <cfcatch type="any">
                                        <cfset percent = 0/>
                                    </cfcatch>
                                    </cftry>
                                    <td align="right">#NumberFormat(percent, "__.__")#</td>
                                </tr>
                            </tbody>
                        </cfloop>
                        <tr>
                        <td colspan="3">&nbsp;</td>
                        </tr>
                        <tr>
                        <td colspan="3">&nbsp;</td>
                        </tr>
                    </cfif>
                    </cfloop>
                </table>        
            </td>
        </tr></tbody></table>
        
        <table><tr><td>
            Count of Total Services&nbsp;<strong>#masterActivityStruct['TotalSerivces']#</strong>
        </td></tr></table>
    
    </cfdocument>

<cfelse>
    
    <table width="100%" cellspacing="2"><tbody><tr>
        <td valign="top">
            <table width="100%">
                <thead>
                    <tr>
                        <th colspan="2" align="left">Billable Services</th>
                    </tr>
                    <tr>
                        <th colspan="2" align="left">&nbsp;</th>
                    </tr>
                    <tr>
                        <th align="left">Activity</th><th align="left">Count</th><th align="left">% of Total</th>
                    </tr>
                </thead>
               <cfloop collection="#serviceColumnStruct#" item="i">
               <cfif i eq "Billable Services" OR i eq "Services">
                    <tbody>
                    <tr>
                    <td colspan="3"><strong>#i#</strong></td>
                    </tr>
                    <tr>
                    <td colspan="3"><hr /></td>
                    </tr>
                    </tbody>                        
                    <cfloop collection="#serviceColumnStruct['#i#']#" item="j">                      
                        <tbody>
                            <tr>
                                <td>#serviceColumnStruct['#i#']['#j#']#</td>
                                <td>#masterActivityStruct['#j#']#</td>
                                <cftry>
                                    <cfset percent = (masterActivityStruct['#j#'] / masterActivityStruct['TotalSerivces']) * 100/>
                                <cfcatch type="any">
                                    <cfset percent = 0/>
                                </cfcatch>
                                </cftry>
                                <td>#NumberFormat(percent, "__.__")#</td>
                            </tr>
                        </tbody>
                    </cfloop>
                    <tr>
                    <td colspan="3">&nbsp;</td>
                    </tr>
                    <tr>
                    <td colspan="3">&nbsp;</td>
                    </tr>
                </cfif>
                </cfloop>                    
            </table>
        </td>
        <td>&nbsp;</td>
        <td valign="top">
            <table width="100%">
                <thead>
                    <tr>
                        <th colspan="2" align="left">Billable Services</th>
                    </tr>
                    <tr>
                        <th colspan="2" align="left">&nbsp;</th>
                    </tr>
                    <tr>
                        <th align="left">Activity</th><th align="left">Count</th><th align="left">% of Total</th>
                    </tr>
                </thead>
                <cfloop collection="#serviceColumnStruct#" item="i">
               <cfif i eq "Family Caregiver" OR i eq "DNKA/Cancellation" OR i eq "Transportation">
                    <tbody>
                    <tr>
                    <td colspan="3"><strong>#i#</strong></td>
                    </tr>
                    <tr>
                    <td colspan="3"><hr /></td>
                    </tr>
                    </tbody>                        
                    <cfloop collection="#serviceColumnStruct['#i#']#" item="j">                     
                        <tbody>
                            <tr>
                                <td>#serviceColumnStruct['#i#']['#j#']#</td>
                                <td>#masterActivityStruct['#j#']#</td>
                                <cftry>
                                    <cfset percent = (masterActivityStruct['#j#'] / masterActivityStruct['TotalSerivces']) * 100/>
                                <cfcatch type="any">
                                    <cfset percent = 0/>
                                </cfcatch>
                                </cftry>
                                <td>#NumberFormat(percent, "__.__")#</td>
                            </tr>
                        </tbody>
                    </cfloop>
                    <tr>
                    <td colspan="3">&nbsp;</td>
                    </tr>
                    <tr>
                    <td colspan="3">&nbsp;</td>
                    </tr>
                </cfif>
                </cfloop>
            </table>        
        </td>
    </tr>
    <tr><td><h3>Count of Total Services&nbsp;<strong>#masterActivityStruct['TotalSerivces']#</strong></h3></td></tr>
    </tbody>
    </table>

</cfif>

<!---HTML footer, closes html and body tags.  Any footer info goes here--->
#BASE.htmlFooter()#
<!---HTML footer, closes html and body tags.  Any footer info goes here--->
</cfoutput>